package 判断两棵树是否相同;

import javax.swing.tree.TreeNode;
import java.util.function.BinaryOperator;

public class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if ((q == null && p != null) || (q != null && p == null)) {
            return false;
        }
        if (q != null && p != null) {
            if (q.val != p.val) {        // 这里不能用相等，因为根相等，左右子树不一定相同
                return false;
            }
        }
        boolean retleft = isSameTree(p.left, q.left);
        boolean retright = isSameTree(p.right, q.right);
        return retleft && retright;

    }

}
